#include "Window.hpp"

Window::Window()
{
    this->window = nullptr;
    this->renderer = nullptr;
}

Window::~Window()
{
}

void Window::SetPosition(int x, int y)
{
    if(this->window != nullptr)
    {
        SDL_SetWindowPosition(this->window, x, y);
    }
}

void Window::SetSize(int width, int height)
{
    if(this->window != nullptr)
    {
        SDL_SetWindowSize(this->window, width, height);
    }
}

void Window::SetTitle(std::string title)
{
    if(this->window != nullptr)
    {
        SDL_SetWindowTitle(this->window, title.c_str());
    }
}

void Window::Destroy()
{
    SDL_DestroyRenderer(this->renderer);
    SDL_DestroyWindow(this->window);
}

bool Window::Create(std::string title, int x, int y, int w, int h, Uint32 flags)
{
    SDL_CreateWindowAndRenderer(w, h, flags, &this->window, &this->renderer);
    SDL_SetWindowPosition(this->window, x, y);
    SDL_SetWindowTitle(this->window, title.c_str());
    return this->window != nullptr;
}

SDL_Renderer *Window::GetRenderer()
{
    if(this->window != nullptr)
    {
        return this->renderer;
    }

    return nullptr;
}

SDL_Rect Window::GetSize()
{
    SDL_Rect rect;

    if(this->window != nullptr)
    {
        SDL_GetWindowPosition(this->window, &rect.x, &rect.y);
        SDL_GetWindowSize(this->window, &rect.w, &rect.h);
    }

    return rect;
}
